package controllers;

import play.*;
import play.data.validation.Required;
import play.data.validation.Valid;
import play.libs.Crypto;
import play.mvc.*;
import utils.Constants;
import utils.Secure;

import java.util.*;

import models.*;

public class Sections extends Application {
	
	public static void edit(Long id,Long storyId){
		Story story = Story.findById(storyId);
		render(story);
	}
	
	public static void save(@Valid Section section){
		if(validation.hasErrors()){
			validation.keep();
			edit(null,section.story.id);
		}
		section.user = User.find("byUsername", session.get(Constants.USERNAME_IN_SESSION)).first();
		section.save();
		Stories.view(section.story.id);
	}
	
}